package com.atguigu.tingshu.order.reciever;

import com.atguigu.tingshu.common.rabbit.constant.MqConst;
import com.atguigu.tingshu.order.service.OrderInfoService;

import com.rabbitmq.client.Channel;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


@Component
@Slf4j
public class OrderReceiver {
    @Autowired
    private OrderInfoService orderInfoService;

    @SneakyThrows
    @RabbitListener(queues= MqConst.QUEUE_CANCEL_ORDER)
    public void cancelOrder(Long orderId, Message message, Channel channel){
        if (orderId != null){
            log.info("取消订单，订单id：{}",orderId);

            orderInfoService.cancelOrder(orderId);
        }
        channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);

    }

}
